package cn.com.ntr.jhclient.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import cn.com.ntr.jhclient.R;
import cn.com.ntr.jhclient.model.JobPosition;
import cn.com.ntr.jhclient.util.CommonUtil;

public class SearchResultAdapter extends EnhancedAdapter<JobPosition> {

	public SearchResultAdapter(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public void addAll(List<JobPosition> list) {
		this.dataList=list;
		notifyDataSetChanged();
	}

	@Override
	protected void bindView(View paramView, Context paramContext, int position) {
		// TODO Auto-generated method stub
		JobPosition job = getItem(position);
		ViewHolder holder = (ViewHolder) paramView.getTag();
		holder.tvCompany.setText(job.getCompany());
		holder.tvDate.setText(job.getDate().split(" ")[0]);
		holder.tvPlace.setText(CommonUtil.formatStr(job.getWorkPlace()));
		holder.tvPosition.setText(job.getPlace());
	}

	@Override
	protected View newView(Context context, int i, ViewGroup viewgroup) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.activity_result_item, null);
		ViewHolder holder = new ViewHolder();
		holder.tvCompany = (TextView) view.findViewById(R.id.tv_company);
		holder.tvDate = (TextView) view.findViewById(R.id.tv_date);
		holder.tvPlace = (TextView) view.findViewById(R.id.tv_place);
		holder.tvPosition = (TextView) view.findViewById(R.id.tv_position);
		view.setTag(holder);
		return view;
	}

	private class ViewHolder {
		TextView tvPosition, tvPlace, tvCompany, tvDate;
	}
}
